package com.sander.guardmanagement.ui.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sander.guardmanagement.R;
import com.sander.guardmanagement.base.BaseActivity;
import com.sander.guardmanagement.model.City;
import com.sander.guardmanagement.response.ResponseHomeGetCityData;
import com.sander.guardmanagement.response.ResponseHomegetHotCitys;
import com.sander.guardmanagement.response.ResponseHomegetHotCitysData;
import com.sander.guardmanagement.ui.model.CityItem;

import java.util.List;

/**
 * Created by sander on 2017/4/10.
 */

public class CityListAdapter extends BaseAdapter {

   public List<ResponseHomegetHotCitysData> list;

    Context context;

    private final LayoutInflater layoutInflater;


    public CityListAdapter(Context context, List<ResponseHomegetHotCitysData> list){
        this.context = context;
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return this.list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CityItem item = null;
        if (convertView == null){
            convertView = this.layoutInflater.inflate(R.layout.cityitem,parent,false);
            TextView textView = (TextView) convertView.findViewById(R.id.cityText);
            item = new CityItem();
            item.setTextView(textView);
            convertView.setTag(item);
        }else{
            item = (CityItem) convertView.getTag();
        }
        ResponseHomegetHotCitysData city = this.list.get(position);
        item.getTextView().setText(city.getCity_name());

        return convertView;
    }
}
